<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="shortcut icon" href="https://q1.qlogo.cn/g?b=qq&nk=1484734552&s=640">
  <title>talk_like_BJY</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.47/vue.global.js"></script>
</head>

<body>
  <div id="app" class="container">
    <div class="title">您想说的北京话：</div>
    <textarea class="padding" v-model="your_word" @change="toBJY" placeholder="输入您想说的北京话"></textarea>
    <div class="title">北京爷这么说：</div>
    <textarea class="padding" v-model="BJY_word" placeholder="北京爷这么说..." disabled></textarea>
    <button @click="copyToClipboard">复制北京爷的话</button>
  </div>
</body>

<script>
  const {
    createApp,
    ref,
    computed,
    reactive
  } = Vue

  const app = createApp({
    setup() {
      let your_word = ref('')
      let random_str = reactive([
        '不说话装高手？',
        '空的，你复制尼玛呢？'
      ])

      const toBJY = () => {
        console.log(your_word.value)
      }

      const BJY_word = computed(() => {
        return your_word.value.split('').map(char => char + '儿').join('');
      })

      const copyToClipboard = () => {
        if (!your_word.value) {
            alert(random_str[Math.floor(Math.random() * random_str.length)])
            return
        }
        const text = BJY_word.value
        navigator.clipboard.writeText(text)
      }

      return {
        your_word,
        BJY_word,
        random_str,
        toBJY,
        copyToClipboard
      }
    }
  })

  app.mount('#app')
</script>

<style>
    * {
        padding: 0;
        margin: 0;
        box-sizing: border-box;
    }

    body {
        width: 100vw;
    }

    #app {
        padding: 10px;
        width: 100%;
    }

    .padding {
        padding: 10px;
    }

    textarea {
        width: 100%;
        height: 100px;
    }
</style>
